package com.cbb.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cbb.lease.mapper.ShopMapper;
import com.cbb.lease.pojo.entity.Shop;
import com.cbb.lease.service.ShopService;
import com.gsj.common.pojo.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-eighth01
 * @description: 这是 Shop接口的实现类
 * @author: 陈斌斌
 * @create: 2021-07-24 19:12
 **/
@Service
public class ShopServiceImpl implements ShopService {

    @Resource
    private ShopMapper shopMapper;

    @Override
    public R getAllShop() {
        List<Shop> shops = shopMapper.selectList(null);
        return R.ok().put("shop",shops);
    }

    @Override
    public R getAllShopPage(Integer currentPage, Integer pageSize, Shop shop) {
        Page<Shop> shopPage = new Page<>(currentPage,pageSize);
        QueryWrapper<Shop> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(shop.getShopName())){queryWrapper.like("shop_name",shop.getShopName());}
        if (StringUtils.isNotEmpty(shop.getAddress())){queryWrapper.like("address",shop.getAddress());}
        Page<Shop> page = shopMapper.selectPage(shopPage, queryWrapper);
        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());
    }

    @Override
    public R delById(Integer id) {
        int i = shopMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R updateShop(Shop shop) {
        int i = shopMapper.updateById(shop);
        return R.ok();
    }

    @Override
    public R addShop(Shop shop) {
        shopMapper.insert(shop);
        return R.ok();
    }
}
